
<!doctype html>
<html lang="en" class="no-js">
  <head>
    
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      
        <meta name="description" content="MixPage是个网页自动化工具。既能控制浏览器，也能收发数据包。可兼顾便利性和高效率。功能强大，语法简洁优雅。">
      
      
        <meta name="author" content="g1879">
      
      
        <link rel="canonical" href="http://g1879.gitee.io/MixPage/page_operation/">
      
      
        <link rel="prev" href="../get_page_info/">
      
      
        <link rel="next" href="../cookies/">
      
      <link rel="icon" href="../assets/images/favicon.png">
      <meta name="generator" content="mkdocs-1.4.2, mkdocs-material-9.0.11">
    
    
      
        <title>🔨 页面操作 - MixPage</title>
      
    
    
      <link rel="stylesheet" href="../assets/stylesheets/main.0d440cfe.min.css">
      
        
        <link rel="stylesheet" href="../assets/stylesheets/palette.2505c338.min.css">
      
      
  
  
    
    
  
    
    
  
    
    
  
    
    
  
    
    
  
    
    
  
    
    
  
    
    
  
    
    
  
    
    
  
    
    
  
    
    
  
  
  <style>:root{--md-admonition-icon--note:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M1 7.775V2.75C1 1.784 1.784 1 2.75 1h5.025c.464 0 .91.184 1.238.513l6.25 6.25a1.75 1.75 0 0 1 0 2.474l-5.026 5.026a1.75 1.75 0 0 1-2.474 0l-6.25-6.25A1.752 1.752 0 0 1 1 7.775Zm1.5 0c0 .066.026.13.073.177l6.25 6.25a.25.25 0 0 0 .354 0l5.025-5.025a.25.25 0 0 0 0-.354l-6.25-6.25a.25.25 0 0 0-.177-.073H2.75a.25.25 0 0 0-.25.25ZM6 5a1 1 0 1 1 0 2 1 1 0 0 1 0-2Z"/></svg>');--md-admonition-icon--abstract:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M2.5 1.75v11.5c0 .138.112.25.25.25h3.17a.75.75 0 0 1 0 1.5H2.75A1.75 1.75 0 0 1 1 13.25V1.75C1 .784 1.784 0 2.75 0h8.5C12.216 0 13 .784 13 1.75v7.736a.75.75 0 0 1-1.5 0V1.75a.25.25 0 0 0-.25-.25h-8.5a.25.25 0 0 0-.25.25Zm13.274 9.537v-.001l-4.557 4.45a.75.75 0 0 1-1.055-.008l-1.943-1.95a.75.75 0 0 1 1.062-1.058l1.419 1.425 4.026-3.932a.75.75 0 1 1 1.048 1.074ZM4.75 4h4.5a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1 0-1.5ZM4 7.75A.75.75 0 0 1 4.75 7h2a.75.75 0 0 1 0 1.5h-2A.75.75 0 0 1 4 7.75Z"/></svg>');--md-admonition-icon--info:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"/></svg>');--md-admonition-icon--tip:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M3.499.75a.75.75 0 0 1 1.5 0v.996C5.9 2.903 6.793 3.65 7.662 4.376l.24.202c-.036-.694.055-1.422.426-2.163C9.1.873 10.794-.045 12.622.26 14.408.558 16 1.94 16 4.25c0 1.278-.954 2.575-2.44 2.734l.146.508.065.22c.203.701.412 1.455.476 2.226.142 1.707-.4 3.03-1.487 3.898C11.714 14.671 10.27 15 8.75 15h-6a.75.75 0 0 1 0-1.5h1.376a4.484 4.484 0 0 1-.563-1.191 3.835 3.835 0 0 1-.05-2.063 4.647 4.647 0 0 1-2.025-.293.75.75 0 0 1 .525-1.406c1.357.507 2.376-.006 2.698-.318l.009-.01a.747.747 0 0 1 1.06 0 .748.748 0 0 1-.012 1.074c-.912.92-.992 1.835-.768 2.586.221.74.745 1.337 1.196 1.621H8.75c1.343 0 2.398-.296 3.074-.836.635-.507 1.036-1.31.928-2.602-.05-.603-.216-1.224-.422-1.93l-.064-.221c-.12-.407-.246-.84-.353-1.29a2.425 2.425 0 0 1-.507-.441 3.075 3.075 0 0 1-.633-1.248.75.75 0 0 1 1.455-.364c.046.185.144.436.31.627.146.168.353.305.712.305.738 0 1.25-.615 1.25-1.25 0-1.47-.95-2.315-2.123-2.51-1.172-.196-2.227.387-2.706 1.345-.46.92-.27 1.774.019 3.062l.042.19a.884.884 0 0 1 .01.05c.348.443.666.949.94 1.553a.75.75 0 1 1-1.365.62c-.553-1.217-1.32-1.94-2.3-2.768L6.7 5.527c-.814-.68-1.75-1.462-2.692-2.619a3.737 3.737 0 0 0-1.023.88c-.406.495-.663 1.036-.722 1.508.116.122.306.21.591.239.388.038.797-.06 1.032-.19a.75.75 0 0 1 .728 1.31c-.515.287-1.23.439-1.906.373-.682-.067-1.473-.38-1.879-1.193L.75 5.677V5.5c0-.984.48-1.94 1.077-2.664.46-.559 1.05-1.055 1.673-1.353V.75Z"/></svg>');--md-admonition-icon--success:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"/></svg>');--md-admonition-icon--question:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.92 6.085h.001a.749.749 0 1 1-1.342-.67c.169-.339.436-.701.849-.977C6.845 4.16 7.369 4 8 4a2.756 2.756 0 0 1 1.637.525c.503.377.863.965.863 1.725 0 .448-.115.83-.329 1.15-.205.307-.47.513-.692.662-.109.072-.22.138-.313.195l-.006.004a6.24 6.24 0 0 0-.26.16.952.952 0 0 0-.276.245.75.75 0 0 1-1.248-.832c.184-.264.42-.489.692-.661.103-.067.207-.132.313-.195l.007-.004c.1-.061.182-.11.258-.161a.969.969 0 0 0 .277-.245C8.96 6.514 9 6.427 9 6.25a.612.612 0 0 0-.262-.525A1.27 1.27 0 0 0 8 5.5c-.369 0-.595.09-.74.187a1.01 1.01 0 0 0-.34.398ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"/></svg>');--md-admonition-icon--warning:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"/></svg>');--md-admonition-icon--failure:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M2.344 2.343h-.001a8 8 0 0 1 11.314 11.314A8.002 8.002 0 0 1 .234 10.089a8 8 0 0 1 2.11-7.746Zm1.06 10.253a6.5 6.5 0 1 0 9.108-9.275 6.5 6.5 0 0 0-9.108 9.275ZM6.03 4.97 8 6.94l1.97-1.97a.749.749 0 0 1 1.275.326.749.749 0 0 1-.215.734L9.06 8l1.97 1.97a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215L8 9.06l-1.97 1.97a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734L6.94 8 4.97 6.03a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018Z"/></svg>');--md-admonition-icon--danger:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M9.504.43a1.516 1.516 0 0 1 2.437 1.713L10.415 5.5h2.123c1.57 0 2.346 1.909 1.22 3.004l-7.34 7.142a1.249 1.249 0 0 1-.871.354h-.302a1.25 1.25 0 0 1-1.157-1.723L5.633 10.5H3.462c-1.57 0-2.346-1.909-1.22-3.004L9.503.429Zm1.047 1.074L3.286 8.571A.25.25 0 0 0 3.462 9H6.75a.75.75 0 0 1 .694 1.034l-1.713 4.188 6.982-6.793A.25.25 0 0 0 12.538 7H9.25a.75.75 0 0 1-.683-1.06l2.008-4.418.003-.006a.036.036 0 0 0-.004-.009l-.006-.006-.008-.001c-.003 0-.006.002-.009.004Z"/></svg>');--md-admonition-icon--bug:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M4.72.22a.75.75 0 0 1 1.06 0l1 .999a3.488 3.488 0 0 1 2.441 0l.999-1a.748.748 0 0 1 1.265.332.75.75 0 0 1-.205.729l-.775.776c.616.63.995 1.493.995 2.444v.327c0 .1-.009.197-.025.292.408.14.764.392 1.029.722l1.968-.787a.75.75 0 0 1 .556 1.392L13 7.258V9h2.25a.75.75 0 0 1 0 1.5H13v.5c0 .409-.049.806-.141 1.186l2.17.868a.75.75 0 0 1-.557 1.392l-2.184-.873A4.997 4.997 0 0 1 8 16a4.997 4.997 0 0 1-4.288-2.427l-2.183.873a.75.75 0 0 1-.558-1.392l2.17-.868A5.036 5.036 0 0 1 3 11v-.5H.75a.75.75 0 0 1 0-1.5H3V7.258L.971 6.446a.75.75 0 0 1 .558-1.392l1.967.787c.265-.33.62-.583 1.03-.722a1.677 1.677 0 0 1-.026-.292V4.5c0-.951.38-1.814.995-2.444L4.72 1.28a.75.75 0 0 1 0-1.06Zm.53 6.28a.75.75 0 0 0-.75.75V11a3.5 3.5 0 1 0 7 0V7.25a.75.75 0 0 0-.75-.75ZM6.173 5h3.654A.172.172 0 0 0 10 4.827V4.5a2 2 0 1 0-4 0v.327c0 .096.077.173.173.173Z"/></svg>');--md-admonition-icon--example:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M5 5.782V2.5h-.25a.75.75 0 0 1 0-1.5h6.5a.75.75 0 0 1 0 1.5H11v3.282l3.666 5.76C15.619 13.04 14.543 15 12.767 15H3.233c-1.776 0-2.852-1.96-1.899-3.458Zm-2.4 6.565a.75.75 0 0 0 .633 1.153h9.534a.75.75 0 0 0 .633-1.153L12.225 10.5h-8.45ZM9.5 2.5h-3V6c0 .143-.04.283-.117.403L4.73 9h6.54L9.617 6.403A.746.746 0 0 1 9.5 6Z"/></svg>');--md-admonition-icon--quote:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M1.75 2.5h10.5a.75.75 0 0 1 0 1.5H1.75a.75.75 0 0 1 0-1.5Zm4 5h8.5a.75.75 0 0 1 0 1.5h-8.5a.75.75 0 0 1 0-1.5Zm0 5h8.5a.75.75 0 0 1 0 1.5h-8.5a.75.75 0 0 1 0-1.5ZM2.5 7.75v6a.75.75 0 0 1-1.5 0v-6a.75.75 0 0 1 1.5 0Z"/></svg>');}</style>


    
    
    
      
        
        
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
        <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
      
    
    
    <script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
    
      

    
    
    
  </head>
  
  
    
    
      
    
    
    
    
    <body dir="ltr" data-md-color-scheme="slate" data-md-color-primary="" data-md-color-accent="">
  
    
    
      <script>var palette=__md_get("__palette");if(palette&&"object"==typeof palette.color)for(var key of Object.keys(palette.color))document.body.setAttribute("data-md-color-"+key,palette.color[key])</script>
    
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" for="__drawer"></label>
    <div data-md-component="skip">
      
        
        <a href="#_1" class="md-skip">
          Skip to content
        </a>
      
    </div>
    <div data-md-component="announce">
      
    </div>
    
    
      

  

<header class="md-header md-header--lifted" data-md-component="header">
  <nav class="md-header__inner md-grid" aria-label="Header">
    <a href=".." title="MixPage" class="md-header__button md-logo" aria-label="MixPage" data-md-component="logo">
      
  
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg>

    </a>
    <label class="md-header__button md-icon" for="__drawer">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg>
    </label>
    <div class="md-header__title" data-md-component="header-title">
      <div class="md-header__ellipsis">
        <div class="md-header__topic">
          <span class="md-ellipsis">
            MixPage
          </span>
        </div>
        <div class="md-header__topic" data-md-component="header-topic">
          <span class="md-ellipsis">
            
              🔨 页面操作
            
          </span>
        </div>
      </div>
    </div>
    
      <form class="md-header__option" data-md-component="palette">
        
          
          <input class="md-option" data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme="slate" data-md-color-primary="" data-md-color-accent=""  aria-label="Switch to dark mode"  type="radio" name="__palette" id="__palette_1">
          
            <label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_2" hidden>
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a4 4 0 0 0-4 4 4 4 0 0 0 4 4 4 4 0 0 0 4-4 4 4 0 0 0-4-4m0 10a6 6 0 0 1-6-6 6 6 0 0 1 6-6 6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Z"/></svg>
            </label>
          
        
          
          <input class="md-option" data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme="default" data-md-color-primary="" data-md-color-accent=""  aria-label="Switch to light mode"  type="radio" name="__palette" id="__palette_2">
          
            <label class="md-header__button md-icon" title="Switch to light mode" for="__palette_1" hidden>
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 18c-.89 0-1.74-.2-2.5-.55C11.56 16.5 13 14.42 13 12c0-2.42-1.44-4.5-3.5-5.45C10.26 6.2 11.11 6 12 6a6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Z"/></svg>
            </label>
          
        
      </form>
    
    
    
      <label class="md-header__button md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
      </label>
      <div class="md-search" data-md-component="search" role="dialog">
  <label class="md-search__overlay" for="__search"></label>
  <div class="md-search__inner" role="search">
    <form class="md-search__form" name="search">
      <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
      <label class="md-search__icon md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
      </label>
      <nav class="md-search__options" aria-label="Search">
        
        <button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg>
        </button>
      </nav>
      
    </form>
    <div class="md-search__output">
      <div class="md-search__scrollwrap" data-md-scrollfix>
        <div class="md-search-result" data-md-component="search-result">
          <div class="md-search-result__meta">
            Initializing search
          </div>
          <ol class="md-search-result__list" role="presentation"></ol>
        </div>
      </div>
    </div>
  </div>
</div>
    
    
      <div class="md-header__source">
        <a href="https://gitee.com/g1879/MixPage" title="Go to repository" class="md-source" data-md-component="source">
  <div class="md-source__icon md-icon">
    
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.2.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg>
  </div>
  <div class="md-source__repository">
    Gitee
  </div>
</a>
      </div>
    
  </nav>
  
    
      
<nav class="md-tabs" aria-label="Tabs" data-md-component="tabs">
  <div class="md-tabs__inner md-grid">
    <ul class="md-tabs__list">
      
        
  
  


  <li class="md-tabs__item">
    <a href=".." class="md-tabs__link">
      欢迎
    </a>
  </li>

      
        
  
  
    
  


  
  
  
    <li class="md-tabs__item">
      <a href="../introduction/" class="md-tabs__link md-tabs__link--active">
        使用文档
      </a>
    </li>
  

      
    </ul>
  </div>
</nav>
    
  
</header>
    
    <div class="md-container" data-md-component="container">
      
      
        
      
      <main class="md-main" data-md-component="main">
        <div class="md-main__inner md-grid">
          
            
              
              <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    

  


<nav class="md-nav md-nav--primary md-nav--lifted" aria-label="Navigation" data-md-level="0">
  <label class="md-nav__title" for="__drawer">
    <a href=".." title="MixPage" class="md-nav__button md-logo" aria-label="MixPage" data-md-component="logo">
      
  
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54Z"/></svg>

    </a>
    MixPage
  </label>
  
    <div class="md-nav__source">
      <a href="https://gitee.com/g1879/MixPage" title="Go to repository" class="md-source" data-md-component="source">
  <div class="md-source__icon md-icon">
    
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.2.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg>
  </div>
  <div class="md-source__repository">
    Gitee
  </div>
</a>
    </div>
  
  <ul class="md-nav__list" data-md-scrollfix>
    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href=".." class="md-nav__link">
        欢迎
      </a>
    </li>
  

    
      
      
      

  
  
    
  
  
    
    <li class="md-nav__item md-nav__item--active md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2" checked>
      
      
      
        <label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
          使用文档
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_2_label" aria-expanded="true">
        <label class="md-nav__title" for="__nav_2">
          <span class="md-nav__icon md-icon"></span>
          使用文档
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../introduction/" class="md-nav__link">
        🔨 概述
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../create_page_object/" class="md-nav__link">
        🔨 创建页面对象
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../visit_web_page/" class="md-nav__link">
        🔨 访问网页
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../find_page_element/" class="md-nav__link">
        🔨 查找页面元素
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../get_element_info/" class="md-nav__link">
        🔨 获取元素信息
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../element_operation/" class="md-nav__link">
        🔨 元素操作
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../get_page_info/" class="md-nav__link">
        🔨 获取网页信息
      </a>
    </li>
  

            
          
            
              
  
  
    
  
  
    <li class="md-nav__item md-nav__item--active">
      
      <input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
      
      
      
        <label class="md-nav__link md-nav__link--active" for="__toc">
          🔨 页面操作
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <a href="./" class="md-nav__link md-nav__link--active">
        🔨 页面操作
      </a>
      
        

<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
  
  
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon"></span>
      Table of contents
    </label>
    <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#_1" class="md-nav__link">
    ✅️️ 两种模式共有的方法
  </a>
  
    <nav class="md-nav" aria-label="✅️️ 两种模式共有的方法">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#get" class="md-nav__link">
    📌 get()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#change_mode" class="md-nav__link">
    📌 change_mode()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#set_cookies" class="md-nav__link">
    📌 set_cookies()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#cookies_to_session" class="md-nav__link">
    📌 cookies_to_session()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#cookies_to_driver" class="md-nav__link">
    📌 cookies_to_driver()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#download" class="md-nav__link">
    📌 download()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#close_driver" class="md-nav__link">
    📌 close_driver()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#close_session" class="md-nav__link">
    📌 close_session()
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#s" class="md-nav__link">
    ✅️️ s 模式独有方法
  </a>
  
    <nav class="md-nav" aria-label="✅️️ s 模式独有方法">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#post" class="md-nav__link">
    📌 post()
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#d" class="md-nav__link">
    ✅️️ d 模式独有方法
  </a>
  
    <nav class="md-nav" aria-label="✅️️ d 模式独有方法">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#hide_browser" class="md-nav__link">
    📌 hide_browser()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#show_browser" class="md-nav__link">
    📌 show_browser()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#wait_ele" class="md-nav__link">
    📌 wait_ele()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#run_script" class="md-nav__link">
    📌 run_script()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#run_async_script" class="md-nav__link">
    📌 run_async_script()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#run_cdp" class="md-nav__link">
    📌 run_cdp()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#set_timeouts" class="md-nav__link">
    📌 set_timeouts()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#set_ua_to_tab" class="md-nav__link">
    📌 set_ua_to_tab()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#get_session_storage" class="md-nav__link">
    📌 get_session_storage()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#get_local_storage" class="md-nav__link">
    📌 get_local_storage()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#set_session_storage" class="md-nav__link">
    📌 set_session_storage()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#set_local_storage" class="md-nav__link">
    📌 set_local_storage()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#clean_cache" class="md-nav__link">
    📌 clean_cache()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#to_frame" class="md-nav__link">
    📌 to_frame
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#to_tab" class="md-nav__link">
    📌 to_tab()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#create_tab" class="md-nav__link">
    📌 create_tab()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#close_tabs" class="md-nav__link">
    📌 close_tabs()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#close_other_tabs" class="md-nav__link">
    📌 close_other_tabs()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#scroll" class="md-nav__link">
    📌 scroll
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#scroll_to_see" class="md-nav__link">
    📌 scroll_to_see()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#refresh" class="md-nav__link">
    📌 refresh()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#stop_loading" class="md-nav__link">
    📌 stop_loading()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#back" class="md-nav__link">
    📌 back()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#forward" class="md-nav__link">
    📌 forward()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#screenshot" class="md-nav__link">
    📌 screenshot()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#set_window_size" class="md-nav__link">
    📌 set_window_size()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#process_alert" class="md-nav__link">
    📌 process_alert()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#check_page" class="md-nav__link">
    📌 check_page()
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
    </ul>
  
</nav>
      
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../cookies/" class="md-nav__link">
        🔨 cookies 的使用
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../Drission/" class="md-nav__link">
        🔨 Drission 对象
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../work_with_selenium_and_requests/" class="md-nav__link">
        🔨 对接 selenium 及 requests 代码
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../use_other_browser/" class="md-nav__link">
        🔨 使用其它系统或浏览器
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../DriverPage_and_SessionPage/" class="md-nav__link">
        🔨 DriverPage 和 SessionPage
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
  </ul>
</nav>
                  </div>
                </div>
              </div>
            
            
              
              <div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    

<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
  
  
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon"></span>
      Table of contents
    </label>
    <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#_1" class="md-nav__link">
    ✅️️ 两种模式共有的方法
  </a>
  
    <nav class="md-nav" aria-label="✅️️ 两种模式共有的方法">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#get" class="md-nav__link">
    📌 get()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#change_mode" class="md-nav__link">
    📌 change_mode()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#set_cookies" class="md-nav__link">
    📌 set_cookies()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#cookies_to_session" class="md-nav__link">
    📌 cookies_to_session()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#cookies_to_driver" class="md-nav__link">
    📌 cookies_to_driver()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#download" class="md-nav__link">
    📌 download()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#close_driver" class="md-nav__link">
    📌 close_driver()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#close_session" class="md-nav__link">
    📌 close_session()
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#s" class="md-nav__link">
    ✅️️ s 模式独有方法
  </a>
  
    <nav class="md-nav" aria-label="✅️️ s 模式独有方法">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#post" class="md-nav__link">
    📌 post()
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#d" class="md-nav__link">
    ✅️️ d 模式独有方法
  </a>
  
    <nav class="md-nav" aria-label="✅️️ d 模式独有方法">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#hide_browser" class="md-nav__link">
    📌 hide_browser()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#show_browser" class="md-nav__link">
    📌 show_browser()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#wait_ele" class="md-nav__link">
    📌 wait_ele()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#run_script" class="md-nav__link">
    📌 run_script()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#run_async_script" class="md-nav__link">
    📌 run_async_script()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#run_cdp" class="md-nav__link">
    📌 run_cdp()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#set_timeouts" class="md-nav__link">
    📌 set_timeouts()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#set_ua_to_tab" class="md-nav__link">
    📌 set_ua_to_tab()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#get_session_storage" class="md-nav__link">
    📌 get_session_storage()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#get_local_storage" class="md-nav__link">
    📌 get_local_storage()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#set_session_storage" class="md-nav__link">
    📌 set_session_storage()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#set_local_storage" class="md-nav__link">
    📌 set_local_storage()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#clean_cache" class="md-nav__link">
    📌 clean_cache()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#to_frame" class="md-nav__link">
    📌 to_frame
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#to_tab" class="md-nav__link">
    📌 to_tab()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#create_tab" class="md-nav__link">
    📌 create_tab()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#close_tabs" class="md-nav__link">
    📌 close_tabs()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#close_other_tabs" class="md-nav__link">
    📌 close_other_tabs()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#scroll" class="md-nav__link">
    📌 scroll
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#scroll_to_see" class="md-nav__link">
    📌 scroll_to_see()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#refresh" class="md-nav__link">
    📌 refresh()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#stop_loading" class="md-nav__link">
    📌 stop_loading()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#back" class="md-nav__link">
    📌 back()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#forward" class="md-nav__link">
    📌 forward()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#screenshot" class="md-nav__link">
    📌 screenshot()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#set_window_size" class="md-nav__link">
    📌 set_window_size()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#process_alert" class="md-nav__link">
    📌 process_alert()
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#check_page" class="md-nav__link">
    📌 check_page()
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
    </ul>
  
</nav>
                  </div>
                </div>
              </div>
            
          
          
            <div class="md-content" data-md-component="content">
              <article class="md-content__inner md-typeset">
                
                  



  <h1>🔨 页面操作</h1>

<p>本节介绍页面对象可以使用的方法，有些方法是两种模式共有的，有些只有某种模式可以使用。当调用独有方法时，会自动切换到该模式。如调用<code>post()</code>方法时，会先切换到 s 模式，并同步登录信息。</p>
<h2 id="_1">✅️️ 两种模式共有的方法</h2>
<h3 id="get">📌 <code>get()</code></h3>
<p>此方法用于跳转到一个 url，详细用法见“访问网页”章节。</p>
<h3 id="change_mode">📌 <code>change_mode()</code></h3>
<p>此方法用于转换<code>MixPage</code>对象的模式。<br />
切换后默认在目标模式重新跳转到原模式所在 url。</p>
<div class="admonition warning">
<p class="admonition-title">注意</p>
<p>s 模式转 d 模式时，若浏览器当前网址域名和 s 模式不一样，必定会跳转。</p>
</div>
<p><strong>参数：</strong></p>
<ul>
<li><code>mode</code>：目标模式字符串，<code>'s'</code>或<code>'d'</code>，默认转换到另一种</li>
<li><code>go</code>：转换后是否跳转到原模式所在 url</li>
</ul>
<p><strong>返回：</strong><code>None</code></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="kn">from</span> <span class="nn">MixPage</span> <span class="kn">import</span> <span class="n">MixPage</span>
<a id="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a><span class="kn">from</span> <span class="nn">time</span> <span class="kn">import</span> <span class="n">sleep</span>
<a id="__codelineno-0-3" name="__codelineno-0-3" href="#__codelineno-0-3"></a>
<a id="__codelineno-0-4" name="__codelineno-0-4" href="#__codelineno-0-4"></a><span class="c1"># 创建页面对象，默认 d 模式</span>
<a id="__codelineno-0-5" name="__codelineno-0-5" href="#__codelineno-0-5"></a><span class="n">page</span> <span class="o">=</span> <span class="n">MixPage</span><span class="p">()</span>  
<a id="__codelineno-0-6" name="__codelineno-0-6" href="#__codelineno-0-6"></a><span class="c1"># 访问个人中心页面（未登录，重定向到登录页面）</span>
<a id="__codelineno-0-7" name="__codelineno-0-7" href="#__codelineno-0-7"></a><span class="n">page</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;https://gitee.com/profile&#39;</span><span class="p">)</span>  
<a id="__codelineno-0-8" name="__codelineno-0-8" href="#__codelineno-0-8"></a>
<a id="__codelineno-0-9" name="__codelineno-0-9" href="#__codelineno-0-9"></a><span class="c1"># 打印当前模式和登录前的 title</span>
<a id="__codelineno-0-10" name="__codelineno-0-10" href="#__codelineno-0-10"></a><span class="nb">print</span><span class="p">(</span><span class="s1">&#39;当前模式：&#39;</span><span class="p">,</span> <span class="n">page</span><span class="o">.</span><span class="n">mode</span><span class="p">)</span>
<a id="__codelineno-0-11" name="__codelineno-0-11" href="#__codelineno-0-11"></a><span class="nb">print</span><span class="p">(</span><span class="s1">&#39;登录前title：&#39;</span><span class="p">,</span> <span class="n">page</span><span class="o">.</span><span class="n">title</span><span class="p">,</span> <span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>  
<a id="__codelineno-0-12" name="__codelineno-0-12" href="#__codelineno-0-12"></a>
<a id="__codelineno-0-13" name="__codelineno-0-13" href="#__codelineno-0-13"></a><span class="c1"># 使用 d 模式输入账号密码登录</span>
<a id="__codelineno-0-14" name="__codelineno-0-14" href="#__codelineno-0-14"></a><span class="n">page</span><span class="o">.</span><span class="n">ele</span><span class="p">(</span><span class="s1">&#39;#user_login&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">input</span><span class="p">(</span><span class="s1">&#39;your_user_name&#39;</span><span class="p">)</span>  
<a id="__codelineno-0-15" name="__codelineno-0-15" href="#__codelineno-0-15"></a><span class="n">page</span><span class="o">.</span><span class="n">ele</span><span class="p">(</span><span class="s1">&#39;#user_password&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">input</span><span class="p">(</span><span class="s1">&#39;your_password</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
<a id="__codelineno-0-16" name="__codelineno-0-16" href="#__codelineno-0-16"></a><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<a id="__codelineno-0-17" name="__codelineno-0-17" href="#__codelineno-0-17"></a>
<a id="__codelineno-0-18" name="__codelineno-0-18" href="#__codelineno-0-18"></a><span class="c1"># 切换到 session 模式</span>
<a id="__codelineno-0-19" name="__codelineno-0-19" href="#__codelineno-0-19"></a><span class="n">page</span><span class="o">.</span><span class="n">change_mode</span><span class="p">()</span>  
<a id="__codelineno-0-20" name="__codelineno-0-20" href="#__codelineno-0-20"></a>
<a id="__codelineno-0-21" name="__codelineno-0-21" href="#__codelineno-0-21"></a><span class="c1"># 打印当前模式和登录后的 title（）</span>
<a id="__codelineno-0-22" name="__codelineno-0-22" href="#__codelineno-0-22"></a><span class="nb">print</span><span class="p">(</span><span class="s1">&#39;当前模式：&#39;</span><span class="p">,</span> <span class="n">page</span><span class="o">.</span><span class="n">mode</span><span class="p">)</span>
<a id="__codelineno-0-23" name="__codelineno-0-23" href="#__codelineno-0-23"></a><span class="nb">print</span><span class="p">(</span><span class="s1">&#39;登录后title：&#39;</span><span class="p">,</span> <span class="n">page</span><span class="o">.</span><span class="n">title</span><span class="p">)</span>  
</code></pre></div>
<p><strong>输出：</strong></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-1-1" name="__codelineno-1-1" href="#__codelineno-1-1"></a>当前模式：d
<a id="__codelineno-1-2" name="__codelineno-1-2" href="#__codelineno-1-2"></a>登录前title： 登录 - Gitee.com
<a id="__codelineno-1-3" name="__codelineno-1-3" href="#__codelineno-1-3"></a>
<a id="__codelineno-1-4" name="__codelineno-1-4" href="#__codelineno-1-4"></a>当前模式：s
<a id="__codelineno-1-5" name="__codelineno-1-5" href="#__codelineno-1-5"></a>登录后title： 个人资料 - 码云 Gitee.com
</code></pre></div>
<h3 id="set_cookies">📌 <code>set_cookies()</code></h3>
<p>此方法用于设置<code>cookies</code>。<br />
可以接收<code>CookieJar</code>、<code>list</code>、<code>tuple</code>、<code>str</code>、<code>dict</code>格式的<code>cookies</code>。</p>
<p><strong>参数：</strong></p>
<ul>
<li><code>cookies</code>：<code>cookies</code>信息</li>
<li><code>refresh</code>：设置<code>cookies</code>后是否刷新页面</li>
</ul>
<p><strong>返回：</strong><code>None</code></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-2-1" name="__codelineno-2-1" href="#__codelineno-2-1"></a><span class="n">cookies</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="s1">&#39;abc&#39;</span><span class="p">}</span>
<a id="__codelineno-2-2" name="__codelineno-2-2" href="#__codelineno-2-2"></a><span class="n">page</span><span class="o">.</span><span class="n">set_cookies</span><span class="p">(</span><span class="n">cookies</span><span class="p">)</span>
</code></pre></div>
<h3 id="cookies_to_session">📌 <code>cookies_to_session()</code></h3>
<p>此方法用于从<code>WebDriver</code>对象复制<code>cookies</code>到<code>Session</code>对象。</p>
<p><strong>参数：</strong></p>
<ul>
<li><code>copy_user_agent</code>：是否同时复制 user agent 信息</li>
</ul>
<p><strong>返回：</strong><code>None</code></p>
<h3 id="cookies_to_driver">📌 <code>cookies_to_driver()</code></h3>
<p>此方法用于从<code>Session</code>对象复制<code>cookies</code>到<code>WebDriver</code>对象。</p>
<p><strong>参数：</strong></p>
<ul>
<li><code>url</code>：指定 url，默认用当前 url</li>
</ul>
<p><strong>返回：</strong><code>None</code></p>
<h3 id="download">📌 <code>download()</code></h3>
<p>此方法用于下载文件，详细用法见“下载文件”章节。</p>
<h3 id="close_driver">📌 <code>close_driver()</code></h3>
<p>此方法用于关闭<code>WebDriver</code>对象和浏览器。</p>
<p><strong>参数：</strong> 无</p>
<p><strong>返回：</strong><code>None</code></p>
<h3 id="close_session">📌 <code>close_session()</code></h3>
<p>此方法用于关闭<code>Session</code>对象。</p>
<p><strong>参数：</strong> 无</p>
<p><strong>返回：</strong><code>None</code></p>
<h2 id="s">✅️️ s 模式独有方法</h2>
<h3 id="post">📌 <code>post()</code></h3>
<p>此方法用于以 post 方式访问 url，具体用法见“访问网页”章节。</p>
<h2 id="d">✅️️ d 模式独有方法</h2>
<h3 id="hide_browser">📌 <code>hide_browser()</code></h3>
<p>此方法用于隐藏浏览器进程窗口，非最小化，任务栏上也可隐藏。<br />
但若操作过程中有新增标签页，浏览器会重新出现。 只支持 Windows 系统，且只有设置了<code>local_port</code>或<code>debugger_address</code>时生效。</p>
<p><strong>参数：</strong> 无</p>
<p><strong>返回：</strong><code>None</code></p>
<h3 id="show_browser">📌 <code>show_browser()</code></h3>
<p>此方法用于显示被隐藏的浏览器进程。<br />
只支持 Windows 系统，且只有设置了<code>local_port</code>或<code>debugger_address</code>时生效。</p>
<p><strong>参数：</strong> 无</p>
<p><strong>返回：</strong><code>None</code></p>
<h3 id="wait_ele">📌 <code>wait_ele()</code></h3>
<p>此方法用于等待元素到达某种状态。<br />
调用此方法返回一个<code>ElementWaiter</code>对象，调用该对象方法实现各种方式的等待。</p>
<p><strong>参数：</strong></p>
<ul>
<li><code>loc_or_ele</code>：要等待的元素，可以是元素或定位符</li>
<li><code>timeout</code>：等待超时时间，默认使用页面超时时间</li>
</ul>
<p><strong>方法：</strong></p>
<table>
<thead>
<tr>
<th align="center">方法</th>
<th align="center">参数说明</th>
<th align="center">功能</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center"><code>display()</code></td>
<td align="center">无</td>
<td align="center">等待元素从 DOM 显示</td>
</tr>
<tr>
<td align="center"><code>hidden()</code></td>
<td align="center">无</td>
<td align="center">等待元素从 DOM 隐藏</td>
</tr>
<tr>
<td align="center"><code>delete()</code></td>
<td align="center">无</td>
<td align="center">等待元素从 DOM 删除</td>
</tr>
</tbody>
</table>
<p>这些方法返回布尔值，代表是否等待成功。</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-3-1" name="__codelineno-3-1" href="#__codelineno-3-1"></a><span class="c1"># 等待 id 为 div1 的元素显示，超时使用页面设置</span>
<a id="__codelineno-3-2" name="__codelineno-3-2" href="#__codelineno-3-2"></a><span class="n">page</span><span class="o">.</span><span class="n">wait_ele</span><span class="p">(</span><span class="s1">&#39;#div1&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">display</span><span class="p">()</span>
<a id="__codelineno-3-3" name="__codelineno-3-3" href="#__codelineno-3-3"></a>
<a id="__codelineno-3-4" name="__codelineno-3-4" href="#__codelineno-3-4"></a><span class="c1"># 等待 id 为 div1 的元素被删除（使用 loc 元组），设置超时3秒</span>
<a id="__codelineno-3-5" name="__codelineno-3-5" href="#__codelineno-3-5"></a><span class="n">page</span><span class="o">.</span><span class="n">wait_ele</span><span class="p">((</span><span class="n">By</span><span class="o">.</span><span class="n">ID</span><span class="p">,</span> <span class="s1">&#39;div1&#39;</span><span class="p">),</span> <span class="mi">3</span><span class="p">)</span><span class="o">.</span><span class="n">delete</span><span class="p">()</span>
<a id="__codelineno-3-6" name="__codelineno-3-6" href="#__codelineno-3-6"></a>
<a id="__codelineno-3-7" name="__codelineno-3-7" href="#__codelineno-3-7"></a><span class="c1"># 等待已获取到的元素被隐藏</span>
<a id="__codelineno-3-8" name="__codelineno-3-8" href="#__codelineno-3-8"></a><span class="n">ele</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">ele</span><span class="p">(</span><span class="s1">&#39;#div1&#39;</span><span class="p">)</span>
<a id="__codelineno-3-9" name="__codelineno-3-9" href="#__codelineno-3-9"></a><span class="n">page</span><span class="o">.</span><span class="n">wait_ele</span><span class="p">(</span><span class="n">ele</span><span class="p">)</span><span class="o">.</span><span class="n">hidden</span><span class="p">()</span>
</code></pre></div>
<h3 id="run_script">📌 <code>run_script()</code></h3>
<p>此方法用于执行 js 脚本。</p>
<p><strong>参数：</strong></p>
<ul>
<li><code>script</code>：js 脚本文本</li>
<li><code>*args</code>：传入的参数</li>
</ul>
<p><strong>返回：</strong> 脚本执行结果</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-4-1" name="__codelineno-4-1" href="#__codelineno-4-1"></a><span class="c1"># 执行 js 脚本显示弹出框显示 Hello world!</span>
<a id="__codelineno-4-2" name="__codelineno-4-2" href="#__codelineno-4-2"></a><span class="n">page</span><span class="o">.</span><span class="n">run_script</span><span class="p">(</span><span class="s1">&#39;alert(arguments[0]+arguments[1])&#39;</span><span class="p">,</span> <span class="s1">&#39;Hello&#39;</span><span class="p">,</span> <span class="s1">&#39; world!&#39;</span><span class="p">)</span>
</code></pre></div>
<h3 id="run_async_script">📌 <code>run_async_script()</code></h3>
<p>此方法用于以异步方式执行 js 脚本。</p>
<p><strong>参数：</strong></p>
<ul>
<li><code>script</code>：js 脚本文本</li>
<li><code>*args</code>：传入的参数</li>
</ul>
<p><strong>返回：</strong> 脚本执行结果</p>
<h3 id="run_cdp">📌 <code>run_cdp()</code></h3>
<p>此方法用于执行 Chrome DevTools Protocol 语句。cdp
用法详见<a href="https://chromedevtools.github.io/devtools-protocol/">Chrome DevTools Protocol</a>。</p>
<p><strong>参数：</strong></p>
<ul>
<li>
<p><code>cmd</code>：协议项目方法</p>
</li>
<li>
<p><code>**cmd_args</code>：项目参数</p>
</li>
</ul>
<p><strong>返回：</strong> 该语句返回的值</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-5-1" name="__codelineno-5-1" href="#__codelineno-5-1"></a><span class="c1"># 停止页面加载</span>
<a id="__codelineno-5-2" name="__codelineno-5-2" href="#__codelineno-5-2"></a><span class="n">page</span><span class="o">.</span><span class="n">run_cdp</span><span class="p">(</span><span class="s1">&#39;Page.stopLoading&#39;</span><span class="p">)</span>
</code></pre></div>
<h3 id="set_timeouts">📌 <code>set_timeouts()</code></h3>
<p>此方法用于设置三种超时时间，selenium 4 以上版本生效。</p>
<p><strong>参数：</strong></p>
<ul>
<li><code>implicit</code>：查找元素超时时间</li>
<li><code>pageLoad</code>：页面加载超时时间</li>
<li><code>script</code>：脚本运行超时时间</li>
</ul>
<p><strong>返回：</strong><code>None</code></p>
<h3 id="set_ua_to_tab">📌 <code>set_ua_to_tab()</code></h3>
<p>此方法用于为当前 tab 设置 user agent，只在当前 tab 有效。</p>
<p><strong>参数：</strong></p>
<ul>
<li><code>ua</code>：user agent字符串</li>
</ul>
<p><strong>返回：</strong><code>None</code></p>
<h3 id="get_session_storage">📌 <code>get_session_storage()</code></h3>
<p>此方法用于获取 sessionStorage 信息，可获取全部或单个项。</p>
<p><strong>参数：</strong></p>
<ul>
<li><code>item</code>：要获取的项，不设置则返回全部</li>
</ul>
<p><strong>返回：</strong> sessionStorage 一个或所有项内容</p>
<h3 id="get_local_storage">📌 <code>get_local_storage()</code></h3>
<p>此方法用于获取 localStorage 信息，可获取全部或单个项。</p>
<p><strong>参数：</strong></p>
<ul>
<li><code>item</code>：要获取的项，不设置则返回全部</li>
</ul>
<p><strong>返回：</strong> localStorage 一个或所有项内容</p>
<h3 id="set_session_storage">📌 <code>set_session_storage()</code></h3>
<p>此方法用于设置或删除某项 sessionStorage 信息。</p>
<p><strong>参数：</strong></p>
<ul>
<li>
<p><code>item</code>：要设置的项</p>
</li>
<li>
<p><code>value</code>：项的值，设置为False时，删除该项</p>
</li>
</ul>
<p><strong>返回：</strong><code>None</code></p>
<h3 id="set_local_storage">📌 <code>set_local_storage()</code></h3>
<p>此方法用于设置或删除某项 localStorage 信息。</p>
<p><strong>参数：</strong></p>
<ul>
<li>
<p><code>item</code>：要设置的项</p>
</li>
<li>
<p><code>value</code>：项的值，设置为False时，删除该项</p>
</li>
</ul>
<p><strong>返回：</strong><code>None</code></p>
<h3 id="clean_cache">📌 clean_cache()</h3>
<p>此方法用于清除缓存，可选要清除的项。</p>
<p><strong>参数：</strong></p>
<ul>
<li>
<p><code>session_storage</code>：是否清除 sessionstorage</p>
</li>
<li>
<p><code>local_storage</code>：是否清除 localStorage</p>
</li>
<li>
<p><code>cache</code>：是否清除 cache</p>
</li>
<li>
<p><code>cookies</code>：是否清除 cookies</p>
</li>
</ul>
<p><strong>返回：</strong><code>None</code></p>
<h3 id="to_frame">📌 <code>to_frame</code></h3>
<p>此属性用于将页面焦点移到某个<code>frame</code>或<code>iframe</code>。<br />
调用此属性返回一个<code>ToFrame</code>对象，调用该对象的方法实现焦点转移。<br />
这些方法返回值为当前页面对象，可实现下一步的链式操作。</p>
<table>
<thead>
<tr>
<th align="center">方法</th>
<th align="center">参数说明</th>
<th align="center">功能</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center"><code>main()</code></td>
<td align="center">无</td>
<td align="center">切换到顶层框架</td>
</tr>
<tr>
<td align="center"><code>parent(level)</code></td>
<td align="center">第几层上级框架</td>
<td align="center">切换到上级框架，可指定多层</td>
</tr>
<tr>
<td align="center"><code>by_id(id)</code></td>
<td align="center">id 属性</td>
<td align="center">切换到<code>id</code>为该参数的框架</td>
</tr>
<tr>
<td align="center"><code>by_name(name)</code></td>
<td align="center">name 属性</td>
<td align="center">切换到<code>name</code>为该参数的框架</td>
</tr>
<tr>
<td align="center"><code>by_index(index)</code></td>
<td align="center">序号</td>
<td align="center">切换到页面第几个框架，0 开始</td>
</tr>
<tr>
<td align="center"><code>by_loc(loc)</code></td>
<td align="center">定位符</td>
<td align="center">切换到定位符所指框架</td>
</tr>
<tr>
<td align="center"><code>by_ele(ele)</code></td>
<td align="center">框架元素</td>
<td align="center">传入框架元素，切换到该框架</td>
</tr>
</tbody>
</table>
<div class="highlight"><pre><span></span><code><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a><span class="c1"># 切换到主框架</span>
<a id="__codelineno-6-2" name="__codelineno-6-2" href="#__codelineno-6-2"></a><span class="n">page</span><span class="o">.</span><span class="n">to_frame</span><span class="o">.</span><span class="n">main</span><span class="p">()</span>
<a id="__codelineno-6-3" name="__codelineno-6-3" href="#__codelineno-6-3"></a>
<a id="__codelineno-6-4" name="__codelineno-6-4" href="#__codelineno-6-4"></a><span class="c1"># 切换到上 2 级框架</span>
<a id="__codelineno-6-5" name="__codelineno-6-5" href="#__codelineno-6-5"></a><span class="n">page</span><span class="o">.</span><span class="n">to_frame</span><span class="o">.</span><span class="n">parent</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<a id="__codelineno-6-6" name="__codelineno-6-6" href="#__codelineno-6-6"></a>
<a id="__codelineno-6-7" name="__codelineno-6-7" href="#__codelineno-6-7"></a><span class="c1"># 切换到 id 值为 &#39;iframe_id&#39; 的框架</span>
<a id="__codelineno-6-8" name="__codelineno-6-8" href="#__codelineno-6-8"></a><span class="n">page</span><span class="o">.</span><span class="n">to_frame</span><span class="o">.</span><span class="n">by_id</span><span class="p">(</span><span class="s1">&#39;iframe_id&#39;</span><span class="p">)</span>
<a id="__codelineno-6-9" name="__codelineno-6-9" href="#__codelineno-6-9"></a>
<a id="__codelineno-6-10" name="__codelineno-6-10" href="#__codelineno-6-10"></a><span class="c1"># 切换到 name 值为 &#39;iframe_name&#39; 的框架</span>
<a id="__codelineno-6-11" name="__codelineno-6-11" href="#__codelineno-6-11"></a><span class="n">page</span><span class="o">.</span><span class="n">to_frame</span><span class="o">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">&#39;iframe_name&#39;</span><span class="p">)</span>
<a id="__codelineno-6-12" name="__codelineno-6-12" href="#__codelineno-6-12"></a>
<a id="__codelineno-6-13" name="__codelineno-6-13" href="#__codelineno-6-13"></a><span class="c1"># 切换到页面中第一个框架</span>
<a id="__codelineno-6-14" name="__codelineno-6-14" href="#__codelineno-6-14"></a><span class="n">page</span><span class="o">.</span><span class="n">to_frame</span><span class="o">.</span><span class="n">by_index</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<a id="__codelineno-6-15" name="__codelineno-6-15" href="#__codelineno-6-15"></a>
<a id="__codelineno-6-16" name="__codelineno-6-16" href="#__codelineno-6-16"></a><span class="c1"># 使用定位符查找元素，再实现切换</span>
<a id="__codelineno-6-17" name="__codelineno-6-17" href="#__codelineno-6-17"></a><span class="n">page</span><span class="o">.</span><span class="n">to_frame</span><span class="o">.</span><span class="n">by_loc</span><span class="p">(</span><span class="s1">&#39;tag:iframe&#39;</span><span class="p">)</span>
<a id="__codelineno-6-18" name="__codelineno-6-18" href="#__codelineno-6-18"></a>
<a id="__codelineno-6-19" name="__codelineno-6-19" href="#__codelineno-6-19"></a><span class="c1"># 先获取 iframe 元素，再传入实现切换</span>
<a id="__codelineno-6-20" name="__codelineno-6-20" href="#__codelineno-6-20"></a><span class="n">iframe</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">ele</span><span class="p">(</span><span class="s1">&#39;tag:iframe&#39;</span><span class="p">)</span>
<a id="__codelineno-6-21" name="__codelineno-6-21" href="#__codelineno-6-21"></a><span class="n">page</span><span class="o">.</span><span class="n">to_frame</span><span class="o">.</span><span class="n">by_ele</span><span class="p">(</span><span class="n">iframe</span><span class="p">)</span>
</code></pre></div>
<p><code>ToFrame</code>类实现了<code>__call__()</code>方法，可自动判断传入类型，使用比较简便。</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-7-1" name="__codelineno-7-1" href="#__codelineno-7-1"></a><span class="c1"># 切换到 id 值为 &#39;iframe_id&#39; 的框架</span>
<a id="__codelineno-7-2" name="__codelineno-7-2" href="#__codelineno-7-2"></a><span class="n">page</span><span class="o">.</span><span class="n">to_frame</span><span class="p">(</span><span class="s1">&#39;iframe_id&#39;</span><span class="p">)</span>
<a id="__codelineno-7-3" name="__codelineno-7-3" href="#__codelineno-7-3"></a>
<a id="__codelineno-7-4" name="__codelineno-7-4" href="#__codelineno-7-4"></a><span class="c1"># 切换到 name 值为 &#39;iframe_name&#39; 的框架</span>
<a id="__codelineno-7-5" name="__codelineno-7-5" href="#__codelineno-7-5"></a><span class="n">page</span><span class="o">.</span><span class="n">to_frame</span><span class="p">(</span><span class="s1">&#39;iframe_name&#39;</span><span class="p">)</span>
<a id="__codelineno-7-6" name="__codelineno-7-6" href="#__codelineno-7-6"></a>
<a id="__codelineno-7-7" name="__codelineno-7-7" href="#__codelineno-7-7"></a><span class="c1"># 切换到页面中第一个框架</span>
<a id="__codelineno-7-8" name="__codelineno-7-8" href="#__codelineno-7-8"></a><span class="n">page</span><span class="o">.</span><span class="n">to_frame</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<a id="__codelineno-7-9" name="__codelineno-7-9" href="#__codelineno-7-9"></a>
<a id="__codelineno-7-10" name="__codelineno-7-10" href="#__codelineno-7-10"></a><span class="c1"># 使用定位符查找元素，再实现切换</span>
<a id="__codelineno-7-11" name="__codelineno-7-11" href="#__codelineno-7-11"></a><span class="n">page</span><span class="o">.</span><span class="n">to_frame</span><span class="p">(</span><span class="s1">&#39;tag:iframe&#39;</span><span class="p">)</span>
<a id="__codelineno-7-12" name="__codelineno-7-12" href="#__codelineno-7-12"></a>
<a id="__codelineno-7-13" name="__codelineno-7-13" href="#__codelineno-7-13"></a><span class="c1"># 先获取 iframe 元素，再传入实现切换</span>
<a id="__codelineno-7-14" name="__codelineno-7-14" href="#__codelineno-7-14"></a><span class="n">iframe</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">ele</span><span class="p">(</span><span class="s1">&#39;tag:iframe&#39;</span><span class="p">)</span>
<a id="__codelineno-7-15" name="__codelineno-7-15" href="#__codelineno-7-15"></a><span class="n">page</span><span class="o">.</span><span class="n">to_frame</span><span class="p">(</span><span class="n">iframe</span><span class="p">)</span>
</code></pre></div>
<div class="admonition warning">
<p class="admonition-title">注意</p>
<p>新版本删除了<code>to_frame('main')</code>和<code>to_frame('parent')</code>的用法。
请改用<code>page.to_frame.main()</code>和<code>page.to_frame.parent()</code>的写法。</p>
</div>
<h3 id="to_tab">📌 <code>to_tab()</code></h3>
<p>此方法把焦点定位到某个标签页。</p>
<p><strong>参数：</strong></p>
<ul>
<li><code>num_or_handle</code>：标签页序号或 handle 字符串，序号第一个为 0，最后为 -1</li>
</ul>
<p><strong>返回：</strong><code>None</code></p>
<div class="admonition warning">
<p class="admonition-title">注意</p>
<p>以下情况会导致获取到的排序号与视觉效果不一致：1、自动化过程中手动点击标签页；2、浏览器被接管时已打开一个以上标签页。</p>
</div>
<div class="highlight"><pre><span></span><code><a id="__codelineno-8-1" name="__codelineno-8-1" href="#__codelineno-8-1"></a><span class="c1"># 跳转到第一个标签页</span>
<a id="__codelineno-8-2" name="__codelineno-8-2" href="#__codelineno-8-2"></a><span class="n">page</span><span class="o">.</span><span class="n">to_tab</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<a id="__codelineno-8-3" name="__codelineno-8-3" href="#__codelineno-8-3"></a>
<a id="__codelineno-8-4" name="__codelineno-8-4" href="#__codelineno-8-4"></a><span class="c1"># 跳转到 handle 为该字符串的标签页</span>
<a id="__codelineno-8-5" name="__codelineno-8-5" href="#__codelineno-8-5"></a><span class="n">page</span><span class="o">.</span><span class="n">to_tab</span><span class="p">(</span><span class="s1">&#39;xxxxxxxxxxxxxxxxxxxx&#39;</span><span class="p">)</span>
</code></pre></div>
<h3 id="create_tab">📌 <code>create_tab()</code></h3>
<p>此方法用于新建并定位到一个标签页,该标签页在最后面。可指定跳转到一个 url。</p>
<p><strong>参数：</strong></p>
<ul>
<li><code>url</code>：新标签页跳转到的 url</li>
</ul>
<p><strong>返回：</strong><code>None</code></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-9-1" name="__codelineno-9-1" href="#__codelineno-9-1"></a><span class="n">page</span><span class="o">.</span><span class="n">create_tab</span><span class="p">(</span><span class="s1">&#39;http://www.baidu.com&#39;</span><span class="p">)</span>
</code></pre></div>
<h3 id="close_tabs">📌 <code>close_tabs()</code></h3>
<p>此方法用于关闭指定的标签页，标签页可以是序号或 handle 值，可关闭多个。默认关闭当前的。</p>
<div class="admonition warning">
<p class="admonition-title">注意</p>
<p>以下情况会导致获取到的排序号与视觉效果不一致，不能按序号关闭：1、自动化过程中手动点击标签页；2、浏览器被接管时已打开一个以上标签页。</p>
</div>
<p><strong>参数：</strong></p>
<ul>
<li><code>num_or_handles</code>：要保留的标签页序号或 handle，可传入 list 或 tuple，为None时关闭当前页</li>
</ul>
<p><strong>返回：</strong><code>None</code></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-10-1" name="__codelineno-10-1" href="#__codelineno-10-1"></a><span class="c1"># 关闭当前标签页</span>
<a id="__codelineno-10-2" name="__codelineno-10-2" href="#__codelineno-10-2"></a><span class="n">page</span><span class="o">.</span><span class="n">close_tabs</span><span class="p">()</span>
<a id="__codelineno-10-3" name="__codelineno-10-3" href="#__codelineno-10-3"></a>
<a id="__codelineno-10-4" name="__codelineno-10-4" href="#__codelineno-10-4"></a><span class="c1"># 关闭第1、3个标签页</span>
<a id="__codelineno-10-5" name="__codelineno-10-5" href="#__codelineno-10-5"></a><span class="n">page</span><span class="o">.</span><span class="n">close_tabs</span><span class="p">((</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
</code></pre></div>
<h3 id="close_other_tabs">📌 <code>close_other_tabs()</code></h3>
<p>此方法用于关闭指定标签页以外的标签页，标签页可以是序号或 handle 值，可保留多个。默认保留当前的。</p>
<div class="admonition warning">
<p class="admonition-title">注意</p>
<p>以下情况会导致获取到的排序号与视觉效果不一致，不能按序号关闭：1、自动化过程中手动点击标签页；2、浏览器被接管时已打开一个以上标签页。</p>
</div>
<p><strong>参数：</strong></p>
<ul>
<li><code>num_or_handles</code>：要保留的标签页序号或 handle，可传入<code>list</code>或<code>tuple</code>，为<code>None</code>时关闭当前页</li>
</ul>
<p><strong>返回：</strong><code>None</code></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-11-1" name="__codelineno-11-1" href="#__codelineno-11-1"></a><span class="c1"># 关闭除当前标签页外的所有标签页</span>
<a id="__codelineno-11-2" name="__codelineno-11-2" href="#__codelineno-11-2"></a><span class="n">page</span><span class="o">.</span><span class="n">close_other_tabs</span><span class="p">()</span>
<a id="__codelineno-11-3" name="__codelineno-11-3" href="#__codelineno-11-3"></a>
<a id="__codelineno-11-4" name="__codelineno-11-4" href="#__codelineno-11-4"></a><span class="c1"># 关闭除第一个以外的标签页</span>
<a id="__codelineno-11-5" name="__codelineno-11-5" href="#__codelineno-11-5"></a><span class="n">page</span><span class="o">.</span><span class="n">close_other_tabs</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<a id="__codelineno-11-6" name="__codelineno-11-6" href="#__codelineno-11-6"></a>
<a id="__codelineno-11-7" name="__codelineno-11-7" href="#__codelineno-11-7"></a><span class="c1"># 关闭除 handle 为 aaaaa 和 bbbbb 以外的标签页</span>
<a id="__codelineno-11-8" name="__codelineno-11-8" href="#__codelineno-11-8"></a><span class="n">reserve_list</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;aaaaa&#39;</span><span class="p">,</span> <span class="s1">&#39;bbbbb&#39;</span><span class="p">)</span>
<a id="__codelineno-11-9" name="__codelineno-11-9" href="#__codelineno-11-9"></a><span class="n">page</span><span class="o">.</span><span class="n">close_other_tabs</span><span class="p">(</span><span class="n">reserve_list</span><span class="p">)</span>
</code></pre></div>
<h3 id="scroll">📌 <code>scroll</code></h3>
<p>此属性用于以某种方式滚动页面。<br />
调用此属性返回一个<code>Scroll</code>对象，调用该对象方法实现各种方式的滚动。</p>
<table>
<thead>
<tr>
<th align="center">方法</th>
<th align="center">参数说明</th>
<th align="center">功能</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center"><code>to_top()</code></td>
<td align="center">无</td>
<td align="center">滚动到顶端，水平位置不变</td>
</tr>
<tr>
<td align="center"><code>to_bottom()</code></td>
<td align="center">无</td>
<td align="center">滚动到底端，水平位置不变</td>
</tr>
<tr>
<td align="center"><code>to_half()</code></td>
<td align="center">无</td>
<td align="center">滚动到垂直中间位置，水平位置不变</td>
</tr>
<tr>
<td align="center"><code>to_rightmost()</code></td>
<td align="center">无</td>
<td align="center">滚动到最右边，垂直位置不变</td>
</tr>
<tr>
<td align="center"><code>to_leftmost()</code></td>
<td align="center">无</td>
<td align="center">滚动到最左边，垂直位置不变</td>
</tr>
<tr>
<td align="center"><code>to_location(x, y)</code></td>
<td align="center">滚动条坐标值</td>
<td align="center">滚动到指定位置</td>
</tr>
<tr>
<td align="center"><code>up(pixel)</code></td>
<td align="center">滚动的像素</td>
<td align="center">向上滚动若干像素，水平位置不变</td>
</tr>
<tr>
<td align="center"><code>down(pixel)</code></td>
<td align="center">滚动的像素</td>
<td align="center">向下滚动若干像素，水平位置不变</td>
</tr>
<tr>
<td align="center"><code>right(pixel)</code></td>
<td align="center">滚动的像素</td>
<td align="center">向左滚动若干像素，垂直位置不变</td>
</tr>
<tr>
<td align="center"><code>left(pixel)</code></td>
<td align="center">滚动的像素</td>
<td align="center">向右滚动若干像素，垂直位置不变</td>
</tr>
</tbody>
</table>
<div class="highlight"><pre><span></span><code><a id="__codelineno-12-1" name="__codelineno-12-1" href="#__codelineno-12-1"></a><span class="c1"># 页面滚动到底部</span>
<a id="__codelineno-12-2" name="__codelineno-12-2" href="#__codelineno-12-2"></a><span class="n">page</span><span class="o">.</span><span class="n">scroll</span><span class="o">.</span><span class="n">to_bottom</span><span class="p">()</span>
<a id="__codelineno-12-3" name="__codelineno-12-3" href="#__codelineno-12-3"></a>
<a id="__codelineno-12-4" name="__codelineno-12-4" href="#__codelineno-12-4"></a><span class="c1"># 页面滚动到最右边</span>
<a id="__codelineno-12-5" name="__codelineno-12-5" href="#__codelineno-12-5"></a><span class="n">page</span><span class="o">.</span><span class="n">scroll</span><span class="o">.</span><span class="n">to_rightmost</span><span class="p">()</span>
<a id="__codelineno-12-6" name="__codelineno-12-6" href="#__codelineno-12-6"></a>
<a id="__codelineno-12-7" name="__codelineno-12-7" href="#__codelineno-12-7"></a><span class="c1"># 页面向下滚动 200 像素</span>
<a id="__codelineno-12-8" name="__codelineno-12-8" href="#__codelineno-12-8"></a><span class="n">page</span><span class="o">.</span><span class="n">scroll</span><span class="o">.</span><span class="n">down</span><span class="p">(</span><span class="mi">200</span><span class="p">)</span>
<a id="__codelineno-12-9" name="__codelineno-12-9" href="#__codelineno-12-9"></a>
<a id="__codelineno-12-10" name="__codelineno-12-10" href="#__codelineno-12-10"></a><span class="c1"># 滚动到指定位置</span>
<a id="__codelineno-12-11" name="__codelineno-12-11" href="#__codelineno-12-11"></a><span class="n">page</span><span class="o">.</span><span class="n">scroll</span><span class="o">.</span><span class="n">to_location</span><span class="p">(</span><span class="mi">100</span><span class="p">,</span> <span class="mi">300</span><span class="p">)</span>
</code></pre></div>
<h3 id="scroll_to_see">📌 <code>scroll_to_see()</code></h3>
<p>此方法用于滚动页面直到元素可见。</p>
<p><strong>参数：</strong></p>
<ul>
<li><code>loc_or_ele</code>：元素的定位信息，可以是元素、定位符</li>
</ul>
<p><strong>返回：</strong><code>None</code></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-13-1" name="__codelineno-13-1" href="#__codelineno-13-1"></a><span class="c1"># 滚动到某个已获取到的元素</span>
<a id="__codelineno-13-2" name="__codelineno-13-2" href="#__codelineno-13-2"></a><span class="n">ele</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">ele</span><span class="p">(</span><span class="s1">&#39;tag:div&#39;</span><span class="p">)</span>
<a id="__codelineno-13-3" name="__codelineno-13-3" href="#__codelineno-13-3"></a><span class="n">page</span><span class="o">.</span><span class="n">scroll_to_see</span><span class="p">(</span><span class="n">ele</span><span class="p">)</span>
<a id="__codelineno-13-4" name="__codelineno-13-4" href="#__codelineno-13-4"></a>
<a id="__codelineno-13-5" name="__codelineno-13-5" href="#__codelineno-13-5"></a><span class="c1"># 滚动到按定位符查找到的元素</span>
<a id="__codelineno-13-6" name="__codelineno-13-6" href="#__codelineno-13-6"></a><span class="n">page</span><span class="o">.</span><span class="n">scroll_to_see</span><span class="p">(</span><span class="s1">&#39;tag:div&#39;</span><span class="p">)</span>
<a id="__codelineno-13-7" name="__codelineno-13-7" href="#__codelineno-13-7"></a>
<a id="__codelineno-13-8" name="__codelineno-13-8" href="#__codelineno-13-8"></a><span class="c1"># 也可用 selenium 定位符</span>
<a id="__codelineno-13-9" name="__codelineno-13-9" href="#__codelineno-13-9"></a><span class="n">page</span><span class="o">.</span><span class="n">scroll_to_see</span><span class="p">((</span><span class="n">By</span><span class="o">.</span><span class="n">XPATH</span><span class="p">,</span> <span class="s1">&#39;//div&#39;</span><span class="p">))</span>
</code></pre></div>
<h3 id="refresh">📌 <code>refresh()</code></h3>
<p>此方法用于刷新当前页面。</p>
<p><strong>参数：</strong> 无</p>
<p><strong>返回：</strong><code>None</code></p>
<h3 id="stop_loading">📌 <code>stop_loading()</code></h3>
<p>此方法用于强制当前页面加载。</p>
<p><strong>参数：</strong> 无</p>
<p><strong>返回：</strong><code>None</code></p>
<h3 id="back">📌 <code>back()</code></h3>
<p>此方法用于在浏览历史中后退一步。</p>
<p><strong>参数：</strong> 无</p>
<p><strong>返回：</strong><code>None</code></p>
<h3 id="forward">📌 <code>forward()</code></h3>
<p>此方法用于在浏览历史中前进一步。</p>
<p><strong>参数：</strong> 无</p>
<p><strong>返回：</strong><code>None</code></p>
<h3 id="screenshot">📌 <code>screenshot()</code></h3>
<p>此方法用于生成页面可见范围截图。图片为 png 格式。<br />
此方法能够自动处理文件重命名的情况，给新文件后面增加序号。
也可以返回图片的二进制文本。</p>
<p><strong>参数：</strong></p>
<ul>
<li><code>path</code>：图片保存路径</li>
<li><code>filename</code>：图片文件名，可不写后缀，不传入时以页面 title 命名</li>
<li><code>as_bytes</code>：是否已字节形式返回图片，为True时上面两个参数失效</li>
</ul>
<p><strong>返回：</strong> 图片完整路径或字节文本</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-14-1" name="__codelineno-14-1" href="#__codelineno-14-1"></a><span class="n">path</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">screenshot</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;D:\tmp&#39;</span><span class="p">,</span> <span class="s1">&#39;img1&#39;</span><span class="p">)</span>  <span class="c1"># 保存到路径，文件名为img1.png</span>
<a id="__codelineno-14-2" name="__codelineno-14-2" href="#__codelineno-14-2"></a><span class="nb">bytes</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">screenshot</span><span class="p">(</span><span class="n">as_bytes</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>  <span class="c1"># 返回截图二进制文本</span>
</code></pre></div>
<h3 id="set_window_size">📌 <code>set_window_size()</code></h3>
<p>此方法用于设置浏览器窗口大小。<br />
默认最大化，任一参数为 0 最小化。</p>
<p><strong>参数：</strong></p>
<ul>
<li><code>height</code>：浏览器窗口高度</li>
<li><code>width</code>：浏览器窗口宽度</li>
</ul>
<p><strong>返回：</strong><code>None</code></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-15-1" name="__codelineno-15-1" href="#__codelineno-15-1"></a><span class="c1"># 窗口最大化</span>
<a id="__codelineno-15-2" name="__codelineno-15-2" href="#__codelineno-15-2"></a><span class="n">page</span><span class="o">.</span><span class="n">set_window_size</span><span class="p">()</span>
<a id="__codelineno-15-3" name="__codelineno-15-3" href="#__codelineno-15-3"></a>
<a id="__codelineno-15-4" name="__codelineno-15-4" href="#__codelineno-15-4"></a><span class="c1"># 窗口最小化</span>
<a id="__codelineno-15-5" name="__codelineno-15-5" href="#__codelineno-15-5"></a><span class="n">page</span><span class="o">.</span><span class="n">set_window_size</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<a id="__codelineno-15-6" name="__codelineno-15-6" href="#__codelineno-15-6"></a>
<a id="__codelineno-15-7" name="__codelineno-15-7" href="#__codelineno-15-7"></a><span class="c1"># 设置窗口为 800*600</span>
<a id="__codelineno-15-8" name="__codelineno-15-8" href="#__codelineno-15-8"></a><span class="n">page</span><span class="o">.</span><span class="n">set_window_size</span><span class="p">(</span><span class="mi">800</span><span class="p">,</span> <span class="mi">600</span><span class="p">)</span>
</code></pre></div>
<h3 id="process_alert">📌 <code>process_alert()</code></h3>
<p>此方法 用于处理提示框。<br />
它能够设置等待时间，等待提示框出现才进行处理，若超时没等到提示框，返回<code>None</code>。<br />
它可只获取提示框文本而不处理提示框。</p>
<p><strong>参数：</strong></p>
<ul>
<li><code>ok</code>：<code>True</code>表示确认，<code>False</code>表示取消，其它值不会按按钮但依然返回文本值</li>
<li><code>send</code>：处理 prompt 提示框时可输入文本</li>
<li><code>timeout</code>：等待提示框出现的超时时间</li>
</ul>
<p><strong>返回：</strong> 提示框内容文本，未等到提示框则返回<code>None</code></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-16-1" name="__codelineno-16-1" href="#__codelineno-16-1"></a><span class="c1"># 确认提示框并获取提示框文本</span>
<a id="__codelineno-16-2" name="__codelineno-16-2" href="#__codelineno-16-2"></a><span class="n">txt</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">process_alert</span><span class="p">()</span>
<a id="__codelineno-16-3" name="__codelineno-16-3" href="#__codelineno-16-3"></a>
<a id="__codelineno-16-4" name="__codelineno-16-4" href="#__codelineno-16-4"></a><span class="c1"># 点击取消</span>
<a id="__codelineno-16-5" name="__codelineno-16-5" href="#__codelineno-16-5"></a><span class="n">page</span><span class="o">.</span><span class="n">process_alert</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span>
<a id="__codelineno-16-6" name="__codelineno-16-6" href="#__codelineno-16-6"></a>
<a id="__codelineno-16-7" name="__codelineno-16-7" href="#__codelineno-16-7"></a><span class="c1"># 给 prompt 提示框输入文本并点击确定</span>
<a id="__codelineno-16-8" name="__codelineno-16-8" href="#__codelineno-16-8"></a><span class="n">page</span><span class="o">.</span><span class="n">process_alert</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="s1">&#39;some text&#39;</span><span class="p">)</span>
<a id="__codelineno-16-9" name="__codelineno-16-9" href="#__codelineno-16-9"></a>
<a id="__codelineno-16-10" name="__codelineno-16-10" href="#__codelineno-16-10"></a><span class="c1"># 不处理提示框，只获取提示框文本</span>
<a id="__codelineno-16-11" name="__codelineno-16-11" href="#__codelineno-16-11"></a><span class="n">txt</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">process_alert</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>
</code></pre></div>
<h3 id="check_page">📌 <code>check_page()</code></h3>
<p>此方法用于检查页面是否符合预期，它默认返回<code>None</code>，须由子类实现其功能。<br />
用于 POM 模式时，可派生各种页面子类，从而实现检查页面的功能。</p>





                
              </article>
            </div>
          
          
        </div>
        
          <a href="#" class="md-top md-icon" data-md-component="top" hidden>
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12Z"/></svg>
            Back to top
          </a>
        
      </main>
      
        <footer class="md-footer">
  
    
      
      <nav class="md-footer__inner md-grid" aria-label="Footer" >
        
          
          <a href="../get_page_info/" class="md-footer__link md-footer__link--prev" aria-label="Previous: 🔨 获取网页信息" rel="prev">
            <div class="md-footer__button md-icon">
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
            </div>
            <div class="md-footer__title">
              <div class="md-ellipsis">
                <span class="md-footer__direction">
                  Previous
                </span>
                🔨 获取网页信息
              </div>
            </div>
          </a>
        
        
          
          <a href="../cookies/" class="md-footer__link md-footer__link--next" aria-label="Next: 🔨 cookies 的使用" rel="next">
            <div class="md-footer__title">
              <div class="md-ellipsis">
                <span class="md-footer__direction">
                  Next
                </span>
                🔨 cookies 的使用
              </div>
            </div>
            <div class="md-footer__button md-icon">
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4Z"/></svg>
            </div>
          </a>
        
      </nav>
    
  
  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <div class="md-copyright">
  
  
    Made with
    <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
      Material for MkDocs
    </a>
  
</div>
      
    </div>
  </div>
</footer>
      
    </div>
    <div class="md-dialog" data-md-component="dialog">
      <div class="md-dialog__inner md-typeset"></div>
    </div>
    
    <script id="__config" type="application/json">{"base": "..", "features": ["navigation.top", "navigation.tracking", "toc.follow", "content.code.copy", "navigation.tabs", "navigation.tabs.sticky", "header.autohide", "navigation.footer"], "search": "../assets/javascripts/workers/search.db81ec45.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}}</script>
    
    
      <script src="../assets/javascripts/bundle.6df46069.min.js"></script>
      
    
  </body>
</html>